package com.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hotel.annotation.ControllerEndpoint;
import com.hotel.entity.Orders;
import com.hotel.response.Result;
import com.hotel.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Lin
 * @since 2022-06-13
 */
@Api(tags = "订单列表")
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Resource
    private OrdersService ordersService;

    @ApiOperation(value = "获取订单列表")
    @GetMapping("/getOrdersList")
    public Result getOrdersList(@RequestParam(value = "number",required = false) String number,
                                @RequestParam(value = "nickName",required = false)String nickName,
                                @RequestParam(value = "checkoutTime",required = false) String checkoutTime,
                                @RequestParam(value = "status",required = false)Integer status,
                                @RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                @RequestParam(value = "size",required = false,defaultValue = "4")Integer size){
        IPage<Orders> orderList = ordersService.getOrderList(number,nickName,checkoutTime,status,current,size);
        return Result.ok().data("orderList",orderList);
    }

    @ApiOperation(value = "查看订单")
    @GetMapping("/getOrder")
    public Result getOrderDetail(@RequestParam(value = "id") String id){
        List<Orders> orderDetail = ordersService.getOrderDetail(id);
        return Result.ok().data("orderList",orderDetail);
    }

    @ApiOperation(value = "删除订单")
    @RequiresPermissions({"order:delete"})
    @DeleteMapping("/deleteOrder")
    @ControllerEndpoint(exceptionMessage = "删除订单失败", operation = "删除订单")
    public Result deleteOrder(@RequestParam(value = "orderNumber") String orderNumber) {
        int i = ordersService.deleteOrder(orderNumber);
        return Result.ok().data("delete",i);
    }

    @ApiOperation(value = "添加备注")
    @RequiresPermissions({"order:update"})
    @PutMapping("/updateOrderRemark")
    @ControllerEndpoint(exceptionMessage = "添加订单备注失败", operation = "添加订单备注")
    public Result updateOrderRemark(@RequestParam(value = "orderNumber") String orderNumber,
                                    @RequestParam(value = "remark") String remark) {
        int i = ordersService.updateOrderRemark(orderNumber, remark);
        return Result.ok().data("update",i);
    }

    @ApiOperation(value = "订单发货")
    @RequiresPermissions({"order:consignment"})
    @PutMapping("/updateOrderStatus")
    @ControllerEndpoint(exceptionMessage = "订单发货失败", operation = "订单发货")
    public Result updateOrderStatus(@RequestParam(value = "orderNumber") String orderNumber){
        int i = ordersService.updateOrderStatus(orderNumber);
        return Result.ok().data("updateStatus",i);
    }






}

